Skip to content

Two Part Transactions#10

Open
xvi10 wants to merge 2 commits into
masterfrom
two-part-txns
Open

Two Part Transactions#10
xvi10 wants to merge 2 commits into
masterfrom
two-part-txns

Conversation

@xvi10

@xvi10 xvi10 commented Mar 2, 2022

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread contracts/oracle/FastPriceFeed.sol Outdated

// do not call setLastUpdatedAt, if the fast price submitter is not updating then
// the Chainlink price should be used instead since this function does not update all token prices
function setPrice(address _token, uint256 _price) external override onlyAdmin {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the usecase for this? without setLastUpdatedAt new price won't be used after some time threshold anyway

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was meant for the keeper / signer flow, will remove it

Comment thread contracts/oracle/FastPriceFeed.sol Outdated

modifier onlyAdmin() {
require(msg.sender == admin, "FastPriceFeed: forbidden");
require(isAdmin[msg.sender], "FastPriceFeed: forbidden");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it won't bother you maybe change "admin" to something like oracle/updater/etc.? since this role is only used to update price. but admin sounds like it can do everything here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i'll call it updater

Comment thread contracts/oracle/FastPriceFeed.sol Outdated
if (index >= tokens.length) { return; }

uint256 startBit = 32 * j;
uint256 price = (_priceBits >> startBit) & PRICE_BITMASK;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may add some sanity checks here as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like min / max price?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Comment thread contracts/peripherals/Timelock.sol Outdated
Comment thread contracts/peripherals/Timelock.sol
Comment thread contracts/core/PositionManager.sol Outdated
address[] memory _path,
function withdrawFees(address _token, address _receiver) external onlyGov {
uint256 amount = feeReserves[_token];
if(amount == 0) { return; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after if 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix

Comment thread contracts/core/PositionManager.sol Outdated
uint256 public minBlockDelayKeeper;
uint256 public minBlockDelayPublic;

uint256 public lastCreationBlock;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this var is not used (only updated in create position func), do we need it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be checked by the fast price feed to schedule an update, i've added a comment

Comment thread contracts/core/PositionManager.sol Outdated
bool shouldRefundCollateral = false;

if (position.isLong) {
shouldRefundCollateral = IVault(_vault).getMaxPrice(position.indexToken) > position.acceptablePrice;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case position won't be open and collateral will be returned to a user?
probably it's not shoudRefundCollateral but more like shouldOpenPosition? since it's just two different branches – open position or cancel it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will rename

Comment thread contracts/core/PositionManager.sol Outdated

}

function executeIncreasePositionETH() external nonReentrant onlyPositionKeeper {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm i guess executeIncreasePosition should handle both cases

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread contracts/core/PositionManager.sol Outdated
uint256 _sizeDelta,
bool _isLong,
uint256 _price
) external nonReentrant onlyPartners {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case we will implement automatic position opening with e.g. each oracle update we can create IncreaseOrder here as well
that might be more secure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for partners they might want it to be opened immediately, otherwise they should just call createIncreasePosition

Comment thread contracts/referrals/ReferralStorage.sol Outdated
emit Register(msg.sender, _code);
}

function updateAddress(bytes32 _code, address _newAccount) external {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not clear wether it's about referrer or owner
maybe updateReferralCodeOwner(_code, _newOwner)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm. i guess it should be merged with setReferralCodeOwner

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will change it

Comment thread contracts/referrals/ReferralStorage.sol Outdated
emit UpdateAddress(msg.sender, _newAccount, _code);
}

function getReferral(address _account) external override view returns (bytes32, address) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"referral" is a trader, who used code and "referrer" is the code owner?
better to name it getReferrer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will change it

Comment thread contracts/core/RouterV2.sol Outdated
return keccak256(abi.encodePacked(_account, _index));
}

function getPendingRequestLenghts() public view returns (uint256, uint256) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it should be "external" instead of "public"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will change it

Comment thread contracts/core/RouterV2.sol Outdated
IncreasePositionRequest memory request = increasePositionRequests[_key];
require(request.account != address(0), "RouterV2: request does not exist");

bool shouldExecute = _validateCancellation(request.blockNumber, request.blockTime);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldExecute -> shouldCancel

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will change it

Comment thread contracts/core/BasePositionManager.sol Outdated
uint256 nextCollateral = collateral.add(collateralDelta);

uint256 prevLeverage = size.mul(BASIS_POINTS_DIVISOR).div(collateral);
uint256 nextLeverage = nextSize.mul(BASIS_POINTS_DIVISOR + 1).div(nextCollateral);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add 100 here (same logic is in validateIncreaseOrder)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

if (isKeeperCall) {
return _positionBlockNumber.add(minBlockDelayKeeper) <= block.number;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we validate that msg.sender == request.account?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theoretical case:

  • keeper doesn't work
  • much time has passed and trader prefers to cancel request
  • some bot will execute it faster to get fee

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will add it

@xvi10
xvi10 changed the base branch from master to staging March 28, 2022 06:37
@xvi10
xvi10 changed the base branch from staging to master March 28, 2022 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants